
import reqwest from "reqwest"
export const DEPARTMENTS_REQUEST = 'DEPARTMENTS_REQUEST'
export const DEPARTMENTS_RECEIVE = 'DEPARTMENTS_RECEIVE'

export function departmentsRequest(){

  return {type:DEPARTMENTS_REQUEST}

}
export function departmentsReceive(items){

  return {type:DEPARTMENTS_RECEIVE,items}

}

export function fetchDepartments(){
  return function(dispatch){
    dispatch(departmentsRequest)
    reqwest({
      url:"/departmentInfo/allDepartment",
      method:"get"
    }).then(data=>data.data.map(item=>({
      name:item.name,
      id  : item.id
    }))).then(items=>dispatch(departmentsReceive(items)))
  }
}
